/**
 * @author Cabrini
 */
$(document).ready(function(){
	
    $('.disponivel').click(function(event){
        id = $(this).attr('alt');
        if ($(":checked").val()) {
            status = 'A';
        }
        else {
            status = 'I';
        }
        
        $.get('http://' + location.host + '/admin/change/', {
            id: id,
            status: status
        }, function(response){
        });
    });
});

function getPaginatedAdminProducts(url, div){
	 var search = $('#search').val();
	if(search != undefined && search != null){
		url = url + "/search/"+search;
	}
	
    $.get(url, function(data){
        $('#' + div + '').html($(data).find('#list-products').html());
    });
}

function getPaginatedAdminClients(url, div){
	 var search = $('#searchCli').val();
	if(search != undefined && search != null){
		url = url + "/searchCli/"+search;
	}
   $.get(url, function(data){
       $('#' + div + '').html($(data).find('#clients').html());
   });
}

function getPaginatedAdminTransactions(url, div){
	var search = $('#searchTra').val();
	url = url + "?";
	if(search != "" && search != null){
		url = url + "&searchTra="+search;
	}
	var status = $('#status').val();
	if(status != "" && status != null){
		url = url + "&status="+status;
	}
	var initial = $('#initial').val();
	if(initial != "" && initial != null){
		url = url + "&initial="+initial;
	}
	
	var dfinal = $('#final').val();
	if(dfinal != "" && dfinal != null){
		url = url + "&final="+dfinal;
	}
	
	url = url + "&city=" + $('#city').val()
	
  $.get(url, function(data){
      $('#' + div + '').html($(data).find('#transaction').html());
  });
}
